package tree.entity;

import org.example.time.util.LocalDateTimeUtil;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author bbottong
 */
public abstract class BaseDo {


    private Long id;

    private Boolean deleted;


    private LocalDateTime createTime;

    private String createBy;


    private LocalDateTime lastUpdateTime;


    private String lastUpdateBy;

    public static void create(BaseDo jobFailedReasonDo, String rootUsername, Date date) {
        create(jobFailedReasonDo, rootUsername, LocalDateTimeUtil.toDate(date));
    }

    public static void create(BaseDo object, String username, LocalDateTime timestamp) {
        object.setCreateBy(username);
        object.setCreateTime(timestamp);
        object.setLastUpdateTime(timestamp);
        object.setLastUpdateBy(username);
        object.setDeleted(Boolean.FALSE);
    }

    public static void create(BaseDo object, String username) {
        LocalDateTime timestamp = LocalDateTime.now();
        create(object, username, timestamp);
    }

    public static void update(BaseDo object, String username) {
        LocalDateTime timestamp = LocalDateTime.now();
        update(object, username, timestamp);
    }

    public static void update(BaseDo object, String username, LocalDateTime timestamp) {
        object.setLastUpdateBy(username);
        object.setLastUpdateTime(timestamp);
    }

    public static void update(BaseDo jobFailedReasonDo, String rootUsername, Date date) {
        update(jobFailedReasonDo, rootUsername, LocalDateTimeUtil.toDate(date));
    }

    public static void delete(BaseDo object, String username, Date date) {
        delete(object, username, LocalDateTimeUtil.toDate(date));
    }

    public static void delete(BaseDo object, String username, LocalDateTime timestamp) {
        object.setDeleted(Boolean.TRUE);
        object.setLastUpdateBy(username);
        object.setLastUpdateTime(timestamp);
    }

    public static void delete(BaseDo object, String username) {
        LocalDateTime timestamp = LocalDateTime.now();
        delete(object, username, timestamp);
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Boolean getDeleted() {
        return deleted;
    }

    public void setDeleted(Boolean deleted) {
        this.deleted = deleted;
    }

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTimestamp) {
        this.createTime = createTimestamp;
    }

    public String getLastUpdateBy() {
        return lastUpdateBy;
    }

    public void setLastUpdateBy(String lastUpdateBy) {
        this.lastUpdateBy = lastUpdateBy;
    }

    public LocalDateTime getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(LocalDateTime lastUpdateTimestamp) {
        this.lastUpdateTime = lastUpdateTimestamp;
    }

}
